package thread.zjitc.net.lib.HomeWorkShare;

/**
 * @author 朱志文
 * @data 2019/10/24 0024
 */
public class ShareThread {
    private volatile int num;
    private volatile boolean flag;


    public void produce(int i) {
        while (flag) {
        }
        synchronized (this) {
            num = i;
            flag = true;
            System.out.println("生产数量为:" + num);
        }

    }

    public void cunsumer() {
        while (!flag) {
        }
        synchronized (this) {
            flag = false;
            System.out.println("消费数量为:" + num);
        }

    }
}
